package weaver.interfaces.xfjt.action;

import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-01-07
 * @Description: 重点工程建设督查反馈结束后修改周期督办台账状态
 * @ModifyLog:
 **/

public class WeaKeyProjectBackAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        String currentDate = DateUtil.getCurrentDate();
        RecordSet rs = new RecordSet();
        writeLog( ">>>>>WeaKeyProjectBackAction>>>requestid=" + requestid );
        try {
            rs.executeQuery( "select sjid,fkfqrq,xmtjqk,xywcfkrq,dcjsrq,sgjd,dbjhjd from " + tablename + " where requestid=?",requestid );
            rs.next();
            String sjid = Util.null2String( rs.getString( "sjid" ) );
            String fkfqrq = Util.null2String( rs.getString( "fkfqrq" ) );
            String xmtjqk = Util.null2String( rs.getString( "xmtjqk" ));
            String xywcfkrq = Util.null2String( rs.getString( "xywcfkrq" ));
            String dcjsrq = Util.null2String( rs.getString( "dcjsrq" ));
            String sgjd = Util.null2String( rs.getString( "sgjd" ));
            String dbjhjd = Util.null2String( rs.getString( "dbjhjd" ));
            String bsqk = "0";
            if(DateUtil.compDate(currentDate,xywcfkrq)<0){
                bsqk = "1";
            }
            rs.executeUpdate( "update uf_zdgcdc set fkrq='"+currentDate+"',xmtjqk='"+xmtjqk+"'," +
                    "fkfqrq='"+fkfqrq+"',xywcfkrq='"+xywcfkrq+"',sgjd='"+sgjd+"',dbjhjd='"+dbjhjd+"'" +
                    " ,bsqk='"+bsqk+"' where id='"+sjid+"'");
            rs.executeUpdate( "update uf_zdgcdc_dt1 set fkrq='"+currentDate+"',xmtjqk='"+xmtjqk+"'," +
                    "fkfqrq='"+fkfqrq+"',xywcfkrq='"+xywcfkrq+"',sgjd='"+sgjd+"',dbjhjd='"+dbjhjd+"'" +
                    ",bsqk='"+bsqk+"',sfwcfk=0 where mainid='"+sjid+"' and fklc='"+requestid+"'");
            int datevalue = DateUtil.compDate(currentDate,dcjsrq);
            writeLog( ">>>>WeaKeyProjectBackAction>>>datevalue=" + datevalue);
            if(datevalue<0) {
                rs.executeQuery("select sfwcfk from uf_zdgcdc_dt1 where mainid=? ", sjid);
                int counts = rs.getCounts();
                int count = 0;
                while (rs.next()) {
                    String sfwcfk = Util.null2String(rs.getString("sfwcfk"));
                    if ("1".equals(sfwcfk)) {
                        count++;
                    }
                }
                writeLog(">>>>WeaKeyProjectBackAction>>>count=" + count);
                if (count == 0 && counts > 0) {
                    rs.executeUpdate("update uf_zdgcdc set dczt=1 where id=?", sjid);
                }
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}
